<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
	<header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
		<a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
			<span class="aui-iconfont aui-icon-left"></span>
		</a>
		<div class="aui-title" id="title">
			检测模板列表
		</div>
	</header>

	<script id="chkTemp" type="text/x-dot-template">

		{{~ it:value:index}}
		<li class="aui-list-item" onclick="setChkTemplate('{{= it[index].sysid }}','{{= it[index].code }}','{{= it[index].name }}');">
			<div class="aui-list-item-inner">
				<div class="aui-list-item-title">{{= it[index].code }}:{{= it[index].name }}</div>
			</div>
		</li>
		{{~}}

	</script>

	<div class="aui-content aui-margin-b-15" style="margin-top: 70px;">
		<ul class="aui-list aui-form-list">
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">检测类型</div>
					<div class="aui-list-item-input">
						<select id="uqcmBdChkType" onchange="onChange()">
						</select>
					</div>
				</div>
			</li>
		</ul>
		<ul class="aui-list aui-list-in" id="chkTempListUl">

		</ul>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
	apiready = function () {

		//查询检测类型下拉框
		getComBox();
	};

	//检测类型下拉框
	function getComBox() {
		var un = localStorage.getItem("un");
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getUqcmBdChkType";

		var data = {
			values: {
				appVersion: api.appVersion,
				un: un,
			}
		};

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 30,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var map = eval("(" + data + ")");
				if (map.code == "0") {

					var list = eval(map.list);
				var html = "<option value=''>--请选择--</option>";
				for (var i = 0; i < list.length; i++) {
					html += "<option value='" + list[i].sysid + "'>" + list[i].name + "</option>";
				}
				$api.html($api.byId("uqcmBdChkType"), html);
					//失败
				} else if (map.code == "1") {
					api.toast({
						msg: map.message,
						duration: 3000
					});
				}

				// var list = eval(map.list);
				// var html = "<option value=''>--请选择--</option>";
				// for (var i = 0; i < list.length; i++) {
				// 	html += "<option value='" + list[i].sysid + "'>" + list[i].name + "</option>";
				// }
				// $api.html($api.byId("uqcmBdChkType"), html);
			}
		});
	}

	//检测类型下拉框值改变
	function onChange() {
		var mrlCode = api.pageParam.mrlCode;
		var uqcmBdChkType = $("#uqcmBdChkType").val();
		getChkTempByMrl(mrlCode, uqcmBdChkType);
	}

	//查询检测模板
	function getChkTempByMrl(mrlCode, uqcmBdChkType) {
		var un = localStorage.getItem("un");
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getChkTempByMrl";

		var data = {
			values: {
				un: un,
				mrlCode: mrlCode,
				appVersion: api.appVersion,
				uqcmBdChkType: uqcmBdChkType
			}
		};

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 30,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
				var myobj = eval("(" + data + ")");
				if (myobj.code == '0') {
					var mydata = eval(myobj.list);
					var evaluation = doT.template($api.dom('#chkTemp').innerHTML);
					$api.dom('#chkTempListUl').innerHTML = evaluation(mydata);
				} else {
					api.toast({
						msg: myobj.message,
						duration: 3000
					});
				}
			}
		});
	}

	function setChkTemplate(id, code, name) {
		api.closeWin();
		var nameR = api.pageParam.name;
		api.execScript({
			name: nameR,
			script: 'setChkTemplate("' + id + '","' + code + '","' + name + '")'
		});
	}

	function closeWin() {
		api.closeWin();
	}
</script>

</html>